﻿using System;
using System.Threading;
using Microsoft.SPOT.Hardware;
using Nokia.LCDScreens;

namespace RaspberryLed
{
    class Program
    {
        static bool bstop = false;
        static Nokia_5110 Lcd = new Nokia_5110(true, Cpu.Pin.GPIO_08, Cpu.Pin.GPIO_18, Cpu.Pin.GPIO_24, Cpu.Pin.GPIO_17);

        static void Main(string[] args)
        {
            
            Lcd.BacklightBrightness = 75;
            
            // Bitmaps genenerated at https://stefan.co/stco-includes/createbitmap.php
            byte[] Bitmap1 = { 255, 255, 255, 255, 255, 127, 63, 111, 119, 255, 255, 191,
191, 127, 95, 223, 223, 255, 63, 79, 23, 159, 55, 31, 143, 155, 199, 253, 237,
247, 119, 118, 59, 59, 59, 151, 159, 175, 191, 247, 254, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 7, 7, 15, 63, 127, 254, 249, 225, 226, 225,
224, 240, 240, 240, 252, 250, 248, 248, 252, 252, 254, 254, 247, 231, 231, 239,
101, 33, 49, 49, 152, 216, 236, 236, 252, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 6, 6, 7, 7, 3, 3, 3, 1,
3, 255, 255, 255, 255, 255, 191, 191, 189, 185, 249, 249, 121, 121, 120, 120,
124, 124, 124, 94, 95, 223, 207, 255, 255, 255, 255, 255, 239, 247, 255, 251,
255, 255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, 127, 255, 255, 255,
63, 31, 63, 31, 31, 159, 223, 191, 191, 255, 255, 127, 127, 127, 31, 31, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 24, 0, 0, 0, 0, 0, 0, 0,
0, 189, 253, 252, 248, 248, 240, 240, 240, 180, 160, 160, 160, 168, 128, 128,
144, 176, 48, 48, 48, 112, 112, 113, 113, 115, 119, 119, 255, 255, 255, 251,
241, 96, 192, 193, 143, 31, 31, 56, 96, 128, 12, 12, 12, 15, 12, 14, 6, 2, 0,
14, 6, 7, 55, 31, 15, 31, 1, 0, 128, 128, 128, 240, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 31, 193, 0, 56, 16, 0, 0, 0, 0, 128, 248, 251,
251, 219, 209, 147, 131, 131, 131, 3, 3, 5, 1, 1, 1, 1, 3, 2, 2, 38, 38, 102,
78, 76, 76, 92, 94, 127, 159, 131, 129, 32, 96, 80, 16, 136, 228, 4, 68, 6, 242,
254, 254, 254, 254, 254, 254, 248, 248, 240, 240, 244, 242, 242, 246, 254, 254,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 4, 80, 196, 96, 0, 0, 64, 248, 250, 127, 127, 127, 31, 143, 247, 247, 191,
63, 31, 15, 31, 14, 22, 50, 34, 54, 38, 36, 36, 20, 12, 12, 12, 40, 72, 8, 16,
18, 18, 146, 50, 32, 36, 38, 2, 0, 16, 128, 240, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
            byte[] Bitmap2 = { 159, 63, 127, 127, 159, 31, 31, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 60, 159, 195, 225, 240, 56,
14, 7, 3, 1, 0, 0, 0, 4, 3, 128, 192, 224, 254, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 51, 227, 70, 8, 144, 33, 226, 239, 255, 7, 15, 255, 255,
255, 255, 255, 255, 255, 63, 7, 7, 7, 0, 2, 15, 3, 0, 24, 24, 8, 0, 32, 48, 120,
248, 252, 254, 255, 255, 255, 255, 127, 63, 127, 255, 127, 63, 63, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 248, 240, 192, 144, 161, 253, 255, 255, 255, 220, 240, 15, 127, 255,
255, 255, 231, 192, 192, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 252,
255, 63, 31, 31, 31, 127, 252, 240, 240, 230, 240, 248, 255, 255, 255, 255, 255,
255, 255, 255, 127, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 220, 128, 0, 31,
255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 252, 252, 252, 252, 254,
255, 255, 255, 191, 62, 222, 252, 252, 252, 252, 248, 249, 251, 243, 255, 239,
231, 15, 7, 7, 3, 1, 0, 0, 0, 0, 1, 1, 128, 135, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254,
254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 254, 255, 249, 249, 253, 255, 255, 255, 255, 255, 255, 255, 255,
255, 227, 224, 224, 192, 192, 128, 128, 128, 192, 240, 248, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255 };
            byte[] Bitmap3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 224, 248, 248, 248, 248, 248,
240, 248, 240, 248, 248, 252, 252, 252, 248, 224, 224, 224, 64, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 224,
224, 232, 249, 255, 255, 255, 255, 255, 223, 207, 199, 131, 3, 1, 0, 31, 191,
191, 191, 191, 159, 159, 15, 15, 255, 255, 255, 244, 240, 240, 224, 224, 224,
192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255,
255, 255, 255, 255, 255, 255, 199, 203, 129, 137, 137, 153, 147, 255, 16, 124,
254, 239, 255, 199, 135, 159, 155, 218, 124, 125, 255, 199, 255, 255, 255, 255,
255, 255, 255, 16, 16, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127,
255, 255, 255, 255, 255, 255, 241, 224, 248, 254, 255, 255, 255, 255, 255, 231,
192, 224, 224, 224, 240, 204, 174, 190, 254, 254, 252, 160, 128, 127, 255, 255,
255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
255, 127, 63, 151, 223, 127, 127, 255, 252, 255, 255, 255, 255, 255, 223, 158,
158, 30, 158, 14, 6, 130, 67, 241, 232, 135, 195, 205, 231, 97, 240, 191, 63,
255, 223, 59, 255, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
11, 30, 31, 17, 56, 60, 62, 35, 16, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 1,
7, 7, 7, 15, 31, 24, 17, 31, 28, 19, 15, 6, 11, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };


            
            Thread myThread = new Thread(trackConsoleKey);
            myThread.Start();

            while (!bstop)
            {
                // Shows the first bitmap
                Lcd.ByteMap = Bitmap1;
                Lcd.Refresh();
                Thread.Sleep(2000);

                // Shows the second bitmap
                Lcd.ByteMap = Bitmap2;
                Lcd.Refresh();
                Thread.Sleep(2000);

                // Shows the third bitmap
                Lcd.ByteMap = Bitmap3;
                Lcd.Refresh();
                Thread.Sleep(2000);
                Lcd.Clear();
                Lcd.Refresh();

                Lcd.WriteText("    Bonjour        Programmez!");
                Thread.Sleep(2000);
                Lcd.Clear();
                Lcd.Refresh();

            }


        }

        static void trackConsoleKey()
        {
            ConsoleKeyInfo cki;
            while (!bstop)
            {
                if (Console.KeyAvailable)
                {
                    cki = Console.ReadKey();
                    if ((cki.KeyChar == 'z') && (Lcd.BacklightBrightness <= 95))
                        Lcd.BacklightBrightness += 5;
                    if ((cki.KeyChar == 'a') && (Lcd.BacklightBrightness >= 5))
                        Lcd.BacklightBrightness = Lcd.BacklightBrightness - 5;
                    if (cki.KeyChar == ' ')
                        bstop = true;
                    Console.WriteLine("LCD : " + Lcd.BacklightBrightness);
                }
                Thread.Sleep(10);            
            }
        
        }
    }
}
